package com.tm.chargecar.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.chargecar.dto.EvBillDto;
import com.tm.chargecar.dto.SiteBillDto;
import com.tm.chargecar.entity.EvDogcartEntity;
import com.tm.chargecar.entity.SiteDogcartEntity;
import com.tm.chargecar.mapper.ChargingPileTwoWheelersMappr;
import com.tm.chargecar.mapper.EvDogcartMapper;
import com.tm.chargecar.mapper.SiteDogcartMapper;
import com.tm.chargecar.result.Result;
import com.tm.chargecar.service.EvDogcartService;
import com.tm.chargecar.service.SiteDogcartService;
import com.tm.chargecar.utils.PageUtil;
import com.tm.chargecar.vo.EvDogcartVo;
import com.tm.chargecar.vo.SiteDogcartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangJie
 * @create 2022-08-24 14:10
 */
@Service
public class EvDogcartServiceImpl extends ServiceImpl<EvDogcartMapper, EvDogcartEntity> implements EvDogcartService {


    @Autowired
    private EvDogcartMapper evDogcartMapper;

    @Autowired
    private ChargingPileTwoWheelersMappr chargingPileTwoWheelersMappr;
    @Override
    public Result queryEv(EvDogcartVo ev) {
        //查询所有站点
        List<EvDogcartEntity> list = evDogcartMapper.queryEv();
        //循环添加设备数
        for (int i = 0; i < list.size(); i++) {
            /**
             * 待定
             */
           Long num = chargingPileTwoWheelersMappr.queryBySiteNum(list.get(i).getEvNum());
           list.get(i).setEvDogcartnum(num);
           Long sum = num*10;
           list.get(i).setEvInterface(sum);
            evDogcartMapper.updateEv(list.get(i));
        }
        PageUtil pageUtil = new PageUtil();
        Long totalCount = evDogcartMapper.queryCount();
        pageUtil.setTotalCount(totalCount);
        List<EvDogcartEntity> data = evDogcartMapper.queryEvPage(ev);
        pageUtil.setData(data);
        return Result.SUCCESS(data);
    }

    @Override
    public void insertEv(EvDogcartEntity evDogcartEntity) {
        long newTime = System.currentTimeMillis();
        evDogcartEntity.setEvOnlinetime(newTime);
        evDogcartMapper.insertEv(evDogcartEntity);

    }

    @Override
    public void updateState(EvDogcartEntity evDogcartEntity) {
        if (evDogcartEntity.getEvState()==1){
            evDogcartEntity.setEvState(0);
        }else{
            evDogcartEntity.setEvState(1);
        }
        evDogcartMapper.updateState(evDogcartEntity);
    }

    @Override
    public void updateAll(EvDogcartEntity evDogcartEntity) {
        evDogcartMapper.updateAll(evDogcartEntity);
    }

    @Override
    public Object queryByEvNum(EvDogcartEntity evDogcartEntity) {
       List<EvBillDto> list = evDogcartMapper.queryByEvNum(evDogcartEntity);

        return list;
    }


}
